package Date;

import org.junit.jupiter.api.Test;

import java.util.Calendar;
import java.util.Date;

public class CalendarTest {
    public static void main(String[] args) {

        //设置中国 前一周的周几
        String time = "15";
        //周几
        String day = "1";
        //前几周
        String week = "3";

        Calendar preDate = Calendar.getInstance();

        Integer integer = Integer.valueOf(day);
        if (integer == 7) {
            preDate.add(Calendar.WEEK_OF_MONTH, -Integer.valueOf(week) +1);
            preDate.set(Calendar.DAY_OF_WEEK, preDate.getFirstDayOfWeek() + integer);
        } else {
            preDate.add(Calendar.WEEK_OF_MONTH, -Integer.valueOf(week));
            preDate.set(Calendar.DAY_OF_WEEK, preDate.getFirstDayOfWeek() + integer);
        }
        preDate.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time));

        System.out.println(preDate.getTime().toLocaleString());



    }
    @Test
    public void test(){
        String[] time = "17:00".split(":|：");
        String day = "24";
        String month = "2";

        //昨天
        Calendar preDate = Calendar.getInstance();
        preDate.add(Calendar.MONTH, -Integer.valueOf(month));
        preDate.set(Calendar.DATE,Integer.valueOf(day));
        preDate.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time[0]));
        System.out.println(preDate.getTime().toLocaleString());
    }
}
